package com.biejiaogroup.librarymanager.controller;

import com.biejiaogroup.librarymanager.service.BookService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: JesseChan
 * @Date: 2022/5/6
 */
@WebServlet("/returnBook")
public class ReturnServlet extends HttpServlet {
    private BookService returnService = new BookService();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String bookID = request.getParameter("bookID");
        PrintWriter out = response.getWriter();

        boolean res = returnService.returnBook(Integer.parseInt(bookID));
        if(res) out.print("success");
        else out.print("fail");
    }
}
